""" 
    Bookshelf - twExtJS sample use with Pylons
    
    Distributed under the terms of Lesser GNU Public License
    (c) 2007 - Ricardo Girardi Sixel 
"""

from pylons import config
from sqlalchemy import Column, MetaData, Table, types
from sqlalchemy.orm import mapper, relation
from sqlalchemy.orm import scoped_session, sessionmaker

# Global session manager.  Session() returns the session object appropriate for the current web request.
Session = scoped_session(sessionmaker(autoflush=True, transactional=True, bind=config['pylons.g'].sa_engine))


# Global metadata. If you have multiple databases with overlapping table names, you'll need a metadata for each
# database.
metadata = MetaData()

book_table = Table('book', metadata,
    Column('id', types.Integer, primary_key=True),
    Column('title', types.Unicode(200), nullable=False),
    Column('authors', types.Unicode(200), nullable=False),
    Column('isbn', types.Unicode(13), nullable=False),
    Column('publisher', types.Unicode(20), nullable=False),
    Column('edition', types.Integer,)
)

class Book(object):
    
    def __str__(self):
        return self.matricula
    
mapper(Book, book_table)